import cn.hutool.core.io.FileUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;

import javax.swing.filechooser.FileSystemView;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;

public class 生成测试JSON文件 {
	public static void main(String[] args) throws InterruptedException {
		for (int i = 0; i < 5; i++) {
			JSONArray jsonArray = new JSONArray();
			jsonArray.put(new JSONObject() {{
				putByPath("name", "张三");
				putByPath("age", "13");
				putByPath("address", "北京");
			}});
			jsonArray.put(new JSONObject() {{
				putByPath("name", "李四");
				putByPath("age", "14");
				putByPath("address", "上海");
			}});
			JSON jsonObject = new JSONObject();
			jsonObject.putByPath("中间层", jsonArray.toString());
			JSONArray array = new JSONArray() {{
				put(jsonObject);
				put(jsonObject);
			}};
			JSONObject entries = new JSONObject();
			entries.putByPath("测试", array.toString());
			File file = new File(FileSystemView.getFileSystemView().getHomeDirectory(),
					"测试"+new SimpleDateFormat("HH时mm分ss秒").format(new Date()) + ".json");
			FileUtil.writeString(entries.toString(), file, StandardCharsets.UTF_8);
			System.out.println("生成文件位置:" + file.getPath());
			Thread.sleep(1000L);
		}
	}
}


